﻿
@{
    List<EvincePayroll.Data.DynamicMenu> menuList = ViewBag.Menu;
    EvincePayroll.Data.EmployeeData employeeData = ViewBag.UserData as EvincePayroll.Data.EmployeeData;
    var checkin = "";
    string checkInStyle = string.Empty;
    string checkOutStyle = string.Empty;
    List<EvincePayroll.Data.PageTemplateData> list = Session["Templates"] as List<EvincePayroll.Data.PageTemplateData>;
    if (Session["CheckIn"] != null)
    {
        checkin = Session["CheckIn"].ToString();
    }
     if (checkin == "0")
     {
         checkInStyle = "style=display:block;float:right;";
         checkOutStyle = "style=display:none;float:right;";

     }
     else if (checkin == "1")
     {
         checkInStyle = "style=display:none;float:right;";
         checkOutStyle = "style=display:block;float:right;";
     }
    
    
    
}
<script type="text/javascript">
    $(document).ready(function () {
        setupDialogBox('dialog', 'checkout');
        $('#checkin').live('click', function () {
            $.ajax({
                type: "POST",
                url: "/Attendance/CheckIn",

                success: function () {
                    alert("You are logedin system.");
                    $('#checkin').hide();
                    $('#checkout').css({
                        display: 'block'
                    });
                }
            });
        });
        $('#SubmitCheckout').live('click', function () {
            var otherReason = $('#otherReason').val();
            var checkoutReason = $('#checkoutReason').val();
            var reason;
            if (checkoutReason == '') {
                reason = otherReason;
            }
            else {
                reason = checkoutReason;
            }
            if (reason == '') {
                $('#otherReason').css({
                    border: '1px solid red'
                });
            }
            else {
                $.ajax({
                    type: "POST",
                    url: "/Attendance/CheckOut?reason=" + reason,
                    success: function () {
                        $('#checkout').hide();
                        $('#checkin').css({
                            display: 'block'
                        });
                        $('#dialog').dialog("close");
                    }
                });
            }
        });
    });
    function checkLunchRadio() {
        $('#otherReason').hide();
        $('#otherReason').css({
            border: '1px solid black'
        });
        $('#checkoutReason').val('Lunch');
        $('#otherReason').val('');
    }
    function checkDepartureRadio() {
        $('#otherReason').hide();
        $('#otherReason').css({
            border: '1px solid black'
        });
        $('#checkoutReason').val('Departure');
        $('#otherReason').val('');
    }
    function checkOtherRadio() {
        $('#checkoutReason').val('');
        var value = $('#otherRadio').val();
        if (value == 'on') {
            $('#otherReason').show();
        }
    }
    </script>
      <div class="grid_12">
    <ul class="nav main">
    
@foreach (var mp in menuList.Where(p => p.ParentId == "8ebdfd46-08af-4c44-96fd-bb506a593bb1"))
{
    
<li><a href="@mp.URL">@mp.MenuName</a> 
        @if (menuList.Count(p => p.ParentId == mp.MenuId.ToString()) > 0)
        {
            @:<ul>
        }  
        
        @RenderMenuItem(menuList, mp)
       
        @if (menuList.Count(p => p.ParentId == mp.MenuId.ToString()) > 0)
        {
            @:</ul>
        }
       
 </li>
}

 @if (list != null && employeeData.UserRoleString!="Admin")
 {
     foreach (var value in list)
     {
    <li class="ic-grid-tables"><a href="../PageTemplate/Template?pageId=@value.PageId"><span>@value.DisplayTitle</span></a></li>
     }
 }


@if (employeeData.UserRoleString != "Admin")
{
  <li id="checkin" class="ic-grid-tables" @checkInStyle><a  href="#">Check In</a></li>
  <li id="checkout" class="ic-grid-tables" @checkOutStyle><a  href="#">Check Out</a></li>
}
</ul>
<input type="hidden" id="checkoutReason" />
</div>


@helper RenderMenuItem(List<EvincePayroll.Data.DynamicMenu> menuList1, EvincePayroll.Data.DynamicMenu mi)
    {
    foreach (var cp in menuList1.Where(X => X.ParentId == mi.MenuId.ToString()))
    {
      
        
        @:<li>
        <a href="@cp.URL">@cp.MenuName</a>
    
        if (menuList1.Count(p => p.ParentId == cp.MenuId.ToString()) > 0)
        {
           @:<ul>  
        }
        
        @RenderMenuItem(menuList1, cp)
        if (menuList1.Count(p => p.ParentId == cp.MenuId.ToString()) > 0)
        {
          @:</ul>
      }
        else
        {
          @:</li>
      }
    }
}